﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NsfcSurvey.Web;
using NsfcSurvey.Web.BzService;
using NsfcSurvey.Web.Helper;

namespace NsfcSurvey.Web.External
{
    public partial class Index : System.Web.UI.Page
    {
        DataService dataService = new DataService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // CheckSurvey();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //验证密码是否正确 
            string pwd = "nsfc2012";
            if (tbxPassword.Text.ToLower().Equals(pwd))
            {
                string departmentCode = tbxDepartmentCode.Text.Trim();
                string departmentName = tbxDepartment.Text.Trim();
                string username = tbxName.Text.Trim();
                string phone = tbxPhone.Text.Trim();
                string email = tbxEmail.Text.Trim();

                int? cate = null;

                //根据用户输入的单位名称进行字符比对 读取cate1 cate2
                Department department = dataService.GetDepartmentByName(departmentName);
                if (department != null)//数据库存在这个单位
                {
                    cate = department.Category;
                }


                //如果用户是选择的 
                UserHelper.StoreSession(departmentCode, departmentName, username, phone, email, cate);
                Response.Redirect("~/Input.aspx");
            }
            else
            {
                lblMsg.Text = "验证密码错误";
            }

        }


    }
}